package gdconf

import (
	"server_cluster/common/logger"
)

// 抽卡蛋池配置表

type TrailRoleConfig struct {
	Id         int32         `csv:"Id" gorm:"primary_key;autoIncrement:false"` // 试用id
	RoleId     int32         `csv:"RoleId"`
	Level      int32         `csv:"Level"`
	Star       int32         `csv:"Star"`
	Position   int32         `csv:"Position,omitempty"`
	TalentList IntArrayArray `csv:"Talent,omitempty"`

	FightProp1  *FightProp `csv:"Attribute1,omitempty"`  // 战斗属性1
	FightProp2  *FightProp `csv:"Attribute2,omitempty"`  // 战斗属性2
	FightProp3  *FightProp `csv:"Attribute3,omitempty"`  // 战斗属性3
	FightProp4  *FightProp `csv:"Attribute4,omitempty"`  // 战斗属性4
	FightProp5  *FightProp `csv:"Attribute5,omitempty"`  // 战斗属性5
	FightProp6  *FightProp `csv:"Attribute6,omitempty"`  // 战斗属性6
	FightProp7  *FightProp `csv:"Attribute7,omitempty"`  // 战斗属性7
	FightProp8  *FightProp `csv:"Attribute8,omitempty"`  // 战斗属性8
	FightProp9  *FightProp `csv:"Attribute9,omitempty"`  // 战斗属性9
	FightProp10 *FightProp `csv:"Attribute10,omitempty"` // 战斗属性10
	FightProp11 *FightProp `csv:"Attribute11,omitempty"` // 战斗属性11
	FightProp12 *FightProp `csv:"Attribute12,omitempty"` // 战斗属性12
	FightProp13 *FightProp `csv:"Attribute13,omitempty"` // 战斗属性13
	FightProp14 *FightProp `csv:"Attribute14,omitempty"` // 战斗属性14
	FightProp15 *FightProp `csv:"Attribute15,omitempty"` // 战斗属性15
	FightProp16 *FightProp `csv:"Attribute16,omitempty"` // 战斗属性16
	FightProp17 *FightProp `csv:"Attribute17,omitempty"` // 战斗属性17
	FightProp18 *FightProp `csv:"Attribute18,omitempty"` // 战斗属性18
	FightProp19 *FightProp `csv:"Attribute19,omitempty"` // 战斗属性19
	FightProp20 *FightProp `csv:"Attribute20,omitempty"` // 战斗属性20
	FightProp21 *FightProp `csv:"Attribute21,omitempty"` // 战斗属性21
	FightProp22 *FightProp `csv:"Attribute22,omitempty"` // 战斗属性22
	FightProp23 *FightProp `csv:"Attribute23,omitempty"` // 战斗属性23
	FightProp24 *FightProp `csv:"Attribute24,omitempty"` // 战斗属性24
	FightProp25 *FightProp `csv:"Attribute25,omitempty"` // 战斗属性25
	FightProp26 *FightProp `csv:"Attribute26,omitempty"` // 战斗属性26
	FightProp27 *FightProp `csv:"Attribute27,omitempty"` // 战斗属性27
	FightProp28 *FightProp `csv:"Attribute28,omitempty"` // 战斗属性28
	FightProp29 *FightProp `csv:"Attribute29,omitempty"` // 战斗属性29
	FightProp30 *FightProp `csv:"Attribute30,omitempty"` // 战斗属性30
	FightProp31 *FightProp `csv:"Attribute31,omitempty"` // 战斗属性31
	FightProp32 *FightProp `csv:"Attribute32,omitempty"` // 战斗属性32
	FightProp33 *FightProp `csv:"Attribute33,omitempty"` // 战斗属性33
	FightProp34 *FightProp `csv:"Attribute34,omitempty"` // 战斗属性34
	FightProp35 *FightProp `csv:"Attribute35,omitempty"` // 战斗属性35
	FightProp36 *FightProp `csv:"Attribute36,omitempty"` // 战斗属性36
	FightProp37 *FightProp `csv:"Attribute37,omitempty"` // 战斗属性37
	FightProp38 *FightProp `csv:"Attribute38,omitempty"` // 战斗属性38
	FightProp39 *FightProp `csv:"Attribute39,omitempty"` // 战斗属性39
	FightProp40 *FightProp `csv:"Attribute40,omitempty"` // 战斗属性40
	FightProp41 *FightProp `csv:"Attribute41,omitempty"` // 战斗属性41
	FightProp42 *FightProp `csv:"Attribute42,omitempty"` // 战斗属性42
	FightProp43 *FightProp `csv:"Attribute43,omitempty"` // 战斗属性43
	FightProp44 *FightProp `csv:"Attribute44,omitempty"` // 战斗属性44
	FightProp45 *FightProp `csv:"Attribute45,omitempty"` // 战斗属性45
	FightProp46 *FightProp `csv:"Attribute46,omitempty"` // 战斗属性46
	FightProp47 *FightProp `csv:"Attribute47,omitempty"` // 战斗属性47
	FightProp48 *FightProp `csv:"Attribute48,omitempty"` // 战斗属性48
	FightProp49 *FightProp `csv:"Attribute49,omitempty"` // 战斗属性49
	FightProp50 *FightProp `csv:"Attribute50,omitempty"` // 战斗属性50

	FightPropList []*FightProp `gorm:"-" csv:"-"` // 战斗属性列表
}

func (c *TrailRoleConfig) TableName() string {
	return "config_trail_role"
}

func (g *GameDataConfig) loadTrailRoleConfig() {
	g.GameDataMaps.TrailRoleConfigMap = make(map[int32]*TrailRoleConfig)
	for _, trailRoleConfig := range loadTableFromDb[TrailRoleConfig](g.Db) {
		trailRoleConfig.FightPropList = make([]*FightProp, 0)
		if trailRoleConfig.FightProp1 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp1)
		}
		if trailRoleConfig.FightProp2 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp2)
		}
		if trailRoleConfig.FightProp3 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp3)
		}
		if trailRoleConfig.FightProp4 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp4)
		}
		if trailRoleConfig.FightProp5 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp5)
		}
		if trailRoleConfig.FightProp6 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp6)
		}
		if trailRoleConfig.FightProp7 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp7)
		}
		if trailRoleConfig.FightProp8 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp8)
		}
		if trailRoleConfig.FightProp9 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp9)
		}
		if trailRoleConfig.FightProp10 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp10)
		}
		if trailRoleConfig.FightProp11 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp11)
		}
		if trailRoleConfig.FightProp12 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp12)
		}
		if trailRoleConfig.FightProp13 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp13)
		}
		if trailRoleConfig.FightProp14 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp14)
		}
		if trailRoleConfig.FightProp15 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp15)
		}
		if trailRoleConfig.FightProp16 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp16)
		}
		if trailRoleConfig.FightProp17 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp17)
		}
		if trailRoleConfig.FightProp18 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp18)
		}
		if trailRoleConfig.FightProp19 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp19)
		}
		if trailRoleConfig.FightProp20 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp20)
		}
		if trailRoleConfig.FightProp21 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp21)
		}
		if trailRoleConfig.FightProp22 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp22)
		}
		if trailRoleConfig.FightProp23 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp23)
		}
		if trailRoleConfig.FightProp24 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp24)
		}
		if trailRoleConfig.FightProp25 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp25)
		}
		if trailRoleConfig.FightProp26 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp26)
		}
		if trailRoleConfig.FightProp27 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp27)
		}
		if trailRoleConfig.FightProp28 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp28)
		}
		if trailRoleConfig.FightProp29 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp29)
		}
		if trailRoleConfig.FightProp30 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp30)
		}
		if trailRoleConfig.FightProp31 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp31)
		}
		if trailRoleConfig.FightProp32 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp32)
		}
		if trailRoleConfig.FightProp33 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp33)
		}
		if trailRoleConfig.FightProp34 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp34)
		}
		if trailRoleConfig.FightProp35 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp35)
		}
		if trailRoleConfig.FightProp36 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp36)
		}
		if trailRoleConfig.FightProp37 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp37)
		}
		if trailRoleConfig.FightProp38 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp38)
		}
		if trailRoleConfig.FightProp39 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp39)
		}
		if trailRoleConfig.FightProp40 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp40)
		}
		if trailRoleConfig.FightProp41 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp41)
		}
		if trailRoleConfig.FightProp42 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp42)
		}
		if trailRoleConfig.FightProp43 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp43)
		}
		if trailRoleConfig.FightProp44 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp44)
		}
		if trailRoleConfig.FightProp45 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp45)
		}
		if trailRoleConfig.FightProp46 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp46)
		}
		if trailRoleConfig.FightProp47 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp47)
		}
		if trailRoleConfig.FightProp48 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp48)
		}
		if trailRoleConfig.FightProp49 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp49)
		}
		if trailRoleConfig.FightProp50 != nil {
			trailRoleConfig.FightPropList = append(trailRoleConfig.FightPropList, trailRoleConfig.FightProp50)
		}

		g.GameDataMaps.TrailRoleConfigMap[trailRoleConfig.Id] = trailRoleConfig
	}
	logger.Info("TrailRoleConfigMap Count: %v", len(g.GameDataMaps.TrailRoleConfigMap))
}

func (g *GameDataConfig) saveTrailRole() {
	saveTableToDb[TrailRoleConfig](g.Db, readTable[TrailRoleConfig](g.CsvPathPrefix+"TrailRole.csv"))
}

func GetTrailRoleConfig4TrailId(trailId int32) *TrailRoleConfig {
	var data, isOk = CONF.GameDataMaps.TrailRoleConfigMap[trailId]
	if !isOk {
		logger.Error("GetTrailRoleConfig4TrailId failed groupId :%v", trailId)
		return nil
	}
	return data
}

func GetTrailRoleConfigMap4GroupId(groupId int32) []*TrailRoleConfig {
	var roleConfigs = make([]*TrailRoleConfig, 0)
	var roleIds = GetTrailRoleList(groupId)
	if roleIds == nil {
		logger.Error("GetTrailRoleConfigMap4GroupId failed, roleIds is nil, groupId: %v", groupId)
		return nil
	}
	for _, roleId := range roleIds {
		var trailRoleConfig = GetTrailRoleConfig4TrailId(roleId)
		if trailRoleConfig == nil {
			logger.Error("GetTrailRoleConfigMap4GroupId failed, trailRoleConfig is nil, groupId: %v,roleId: %v",
				groupId, roleId)
			return nil
		}
		roleConfigs = append(roleConfigs, trailRoleConfig)
	}
	return roleConfigs
}

func GetTrailRoleConfigMap4Pos(groupId int32) map[int32]*TrailRoleConfig {
	var roleConfigs = make(map[int32]*TrailRoleConfig)
	var roleIds = GetTrailRoleList(groupId)
	if roleIds == nil {
		logger.Error("GetTrailRoleConfigMap4GroupId failed, roleIds is nil, groupId: %v", groupId)
		return nil
	}
	for _, roleId := range roleIds {
		var trailRoleConfig = GetTrailRoleConfig4TrailId(roleId)
		if trailRoleConfig == nil {
			logger.Error("GetTrailRoleConfigMap4GroupId failed, trailRoleConfig is nil, groupId: %v,roleId: %v",
				groupId, roleId)
			return nil
		}
		roleConfigs[trailRoleConfig.Position] = trailRoleConfig
	}
	return roleConfigs
}
